/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.bomt.domain.vo;

import com.baomidou.mybatisplus.annotation.TableName;
import com.comac.ins.bomt.common.enums.BizStepEnum;
import com.comac.ins.bomt.common.enums.BomInfoStatusEnum;
import com.comac.ins.bomt.common.enums.StandardBomSrcTypeEnum;
import com.comac.ins.bomt.domain.DetailStandardV2Bom;
import com.comac.ins.bomt.domain.OriginalBomV2Info;
import com.comac.ins.bomt.domain.StandardBomV2Info;
import com.comac.ins.common.tenant.core.TenantEntity;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.Serial;
import java.util.Date;
import java.util.List;

/**
 * Bom信息V2
 *
 * @author zhanghongyi
 * @date 2024 /8/2 16:10
 * @description BomInfo
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = StandardBomV2Info.class)
public class StandardBomV2InfoVo extends TenantEntity {
    @Serial
    private static final long serialVersionUID = -3591479662887893020L;
    /**
     * Id
     */
    private Long id;

    /**
     * 机型
     */
    private String aircraftModel;
    /**
     * 跟踪Id（用于标记产出数据的业务流程Id）
     */
    private String track;
    /**
     * 子跟踪Id（用于标记产出的业务流程步骤）
     */
    private String subTrack;

    /**
     * 部段
     * */
    private String section;

    /**
     * 主部段
     */
    private String mainSection;

    /**
     * ATA 100
     */
    private String ata;
    /**
     * 主分组类型
     */
    private String groupType;
    /**
     * 子分组类型
     */
    private String subGroupType;

    /**
     * 来源类型
     */
    private String srcType;
    /**
     * 来源描述
     */
    private String srcDesc;

    /**
     * 摘要
     */
    private String summary;

    /**
     * 状态
     */
    private String status;
    /**
     * 业务步骤
     */
    private String bizStep;

    /**
     * 错误信息
     */
    private String errorMsg;

    /**
     * 附加信息
     */
    private String extraInfo;

    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 创建人
     */
    private Long createBy;
    /**
     * 创建人部门
     */
    private Long createDept;
    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 更新人部门
     */
    private Long updateBy;

    public static StandardBomV2InfoVo createFromOriginalBom(OriginalBomV2InfoVo originalBomVo, String mainSection,String section) {
        StandardBomV2InfoVo result = new StandardBomV2InfoVo();
        BeanUtils.copyProperties(originalBomVo, result);
        result.setGroupType(mainSection);
        result.setSubGroupType(section);
        result.setSection(section);
        result.setMainSection(mainSection);
        result.setId(null);
        result.setSrcType(StandardBomSrcTypeEnum.ORIGINAL.getType());
        result.setSrcDesc("原始装机清单转化");
        result.setStatus(BomInfoStatusEnum.DONE.getCode());
        result.setBizStep(BizStepEnum.INIT.getType());
        result.setErrorMsg(null);
        result.setExtraInfo(null);
        return result;
    }
    public static StandardBomV2InfoVo createFromDetails(List<DetailStandardV2BomVo> details, String desc) {
        StandardBomV2InfoVo standardBomV2InfoVo = new StandardBomV2InfoVo();
        standardBomV2InfoVo.setAircraftModel(details.get(0).getAircraftModel());
        standardBomV2InfoVo.setTrack(details.get(0).getTrack());
        standardBomV2InfoVo.setSubTrack(details.get(0).getSubTrack());
        standardBomV2InfoVo.setGroupType(details.get(0).getGroupType());
        standardBomV2InfoVo.setSubGroupType(details.get(0).getSubGroupType());
        standardBomV2InfoVo.setSection(details.get(0).getSection());
        standardBomV2InfoVo.setMainSection(details.get(0).getMainSection());
        standardBomV2InfoVo.setStatus(BomInfoStatusEnum.DONE.getCode());
        standardBomV2InfoVo.setBizStep(BizStepEnum.INIT.getType());
        standardBomV2InfoVo.setSrcType(StandardBomSrcTypeEnum.UPLOAD.getType());
        standardBomV2InfoVo.setSrcDesc(desc);
        standardBomV2InfoVo.setId(null);
        standardBomV2InfoVo.setErrorMsg(null);
        standardBomV2InfoVo.setExtraInfo(null);
        return standardBomV2InfoVo;
    }
}
